<template>
  <div>
    <e-table
      @getList="handleGetList"
      :tableData="tableData"
      :columns="columns"
      :loading="loading"
      :total="total"
    >
      <el-table-column label="附件图片" slot="savePath" align="center">
        <template slot-scope="scope">
          <template v-if="scope.row.savepath && scope.row.savepath.length > 0">
            <el-button
              @click="handlePreview(scope.row)"
              type="text"
            >{{ scope.row.savepath.length }}张</el-button>
          </template>
          <template v-else>无</template>
        </template>
      </el-table-column>
      <el-table-column label="状态" slot="state" align="center">
        <template
          slot-scope="scope"
        >{{ scope.row.auditState === 0 ? '待审核' : ( scope.row.auditState === 1 ? '科室审核通过' : ( scope.row.auditState === 2 ? '最终审核通过' : '审核不通过' ) ) }}</template>
      </el-table-column>
    </e-table>
    <preview-modal ref="previewModal" />
  </div>
</template>

<script>
import { getDeptExamineAll } from '@/api/eval'
import PreviewModal from '@/components/PreviewModal'

export default {
  components: {
    PreviewModal
  },
  data() {
    return {
      tableData: [],
      columns: [
        {
          label: '标题',
          prop: 'applyTitle'
        },
        {
          label: '项目名称',
          prop: 'evalItemName'
        },
        {
          label: '考评标准',
          prop: 'standard'
        },
        {
          label: '日期',
          prop: 'eventDate'
        },
        {
          label: '奖惩形式',
          prop: 'rewardType',
          formatter(row, column, cellValue, index) {
            return cellValue === 1 ? '奖' : ' 惩'
          }
        },
        {
          label: '奖惩值',
          prop: 'rewardValue'
        },
        {
          label: '责任人',
          prop: 'targetUser'
        },
        {
          label: '责任科室',
          prop: 'targetDept'
        },
        { slot: 'state' },
        {
          slot: 'savePath'
        },
        {
          label: '事件描述',
          prop: 'eventDescribe'
        }
      ],
      loading: false,
      queryParam: {
        pageSize: 10,
        pageNo: 1
      },
      total: 1
    }
  },
  mounted() {
    this.handleGetList()
  },
  methods: {
    handlePreview(row) {
      this.$refs.previewModal.show(row.savepath)
    },
    refresh() {
      this.handleGetList()
    },
    async handleGetList(param = {}) {
      this.loading = true
      this.queryParam = Object.assign(this.queryParam, param)
      const res = await getDeptExamineAll(this.queryParam)
      if (res.data && res.data.records.length > 0) {
        const {
          state,
          data: { records, total }
        } = res
        this.tableData = records
        this.total = total
      } else {
        this.tableData = []
        this.total = 1
      }
      this.loading = false
    }
  }
}
</script>